package com.yzy.fly.type;

import lombok.Getter;
import lombok.Setter;
import org.apache.commons.lang3.StringUtils;

public enum SQLAnnotationType {

    SELECT("Select","org/apache/ibatis/annotations/Select"),
    UPDATE("Update","org/apache/ibatis/annotations/Update"),
    INSERT("Insert","org/apache/ibatis/annotations/Insert"),
    DELETE("Delete","org/apache/ibatis/annotations/Delete"),
    CALLABLE("CALLABLE","");

    @Setter@Getter
    private String type;
    @Setter@Getter
    private String value;

    SQLAnnotationType(String type, String value){
        this.type = type;
        this.value = value;
    }

    public static SQLAnnotationType type(String type){
        if (StringUtils.isBlank(type)) {
            return null;
        }
        SQLAnnotationType sqlAnnotationType = null;
        SQLAnnotationType[] values = values();
        try {
            for (int i = 0; i < values.length; i++) {
                SQLAnnotationType value = values[i];
                if (value.getType().equals(type)) {
                    sqlAnnotationType = value;
                    break;
                }
            }
        } catch (IllegalArgumentException e) {
            e.printStackTrace();
            sqlAnnotationType = null;
        }
        return sqlAnnotationType;
    }


    public static SQLAnnotationType typeIgnoreCase(String type){
        if (StringUtils.isBlank(type)) {
            return null;
        }
        SQLAnnotationType value = null;
        try {
            SQLAnnotationType[] values = values();
            for (int i = 0; i < values.length; i++) {
                if (values[i].getType().equalsIgnoreCase(type)) {
                    return values[i];
                }
            }
        } catch (IllegalArgumentException e) {
            e.printStackTrace();
            value = null;
        }
        return value;
    }

    public static void main(String[] args) {
        SQLAnnotationType type = type("year");
        int i =0;
    }
}
